package main

import (
	"fmt"

	"github.com/gomodule/redigo/redis"
)

var pool *redis.Pool

func init() {
	pool = &redis.Pool{
		MaxIdle:     8,
		MaxActive:   0,
		IdleTimeout: 100,
		Dial: func() (redis.Conn, error) {
			return redis.Dial("tcp", "localhost:6379")
		},
	}
}

func main() {
	conn := pool.Get()
	defer conn.Close()

	_, err := conn.Do("set", "name", "tomjerrry 猫猫")
	if err != nil {
		fmt.Println("conn.Do err=", err)
		return
	}

	r, err := redis.String(conn.Do("get", "name"))
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("操作ok", r)
	conn.Do("hset", "user1", "name", "pei", "high", "1.68")
	r1, err := redis.Strings(conn.Do("hgetall", "user1"))
	if err != nil {
		fmt.Println(err)
	}
	for i, v := range r1 {
		fmt.Println(i, v)
	}
	r1, err = redis.Strings(conn.Do("keys", "*"))
	if err != nil {
		fmt.Println(err)
	}
	for i, v := range r1 {
		fmt.Println(i, v)
	}

	r1, err = redis.Strings(conn.Do("hkeys", "users"))
	if err != nil {
		fmt.Println(err)
	}
	for i, v := range r1 {
		fmt.Println(i, v)
	}
}
